{template 'header'}
<body>

<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="x-red">*</span>任务金额</label>
            <div class="layui-input-inline">
                <input name="task_money" placeholder="请输入金额" class="layui-input" id="task_money" lay-verify="task_money" value="{$setting['task_money']}">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="x-red">*</span>分享要求</label>
            <div class="layui-input-block">
                <textarea name="detail" placeholder="请输入内容" class="layui-textarea" id="detail" lay-verify="detail">{$setting['detail']}</textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="x-red">*</span>发圈标题</label>
            <div class="layui-input-block">
                <input name="share_title" placeholder="请输入金额" class="layui-input" id="share_title" lay-verify="share_title" value="{$setting['share_title']}">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="x-red">*</span>发圈内容</label>
            <div class="layui-input-block">
                <textarea name="share_content" placeholder="请输入内容" class="layui-textarea" id="share_content" lay-verify="share_content">{$setting['share_content']}</textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="x-red">*</span>分享图片</label>
            <div class="layui-input-block">
                <input type="hidden" name="thumb1" value="{$setting['thumb1']}" id="thumb1">
                <div id="preview-thumb1">
                    {if !empty($setting['thumb1'])}
                    <img src="{php echo cmf_get_upload_url($setting['thumb1'])}" alt="" width="200" height="150">
                    {/if}
                </div>
                <button type="button" class="layui-btn" id="thumb1-btn">
                    <i class="layui-icon">&#xe654;</i>上传图片
                </button>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="x-red">*</span>分享图片2</label>
            <div class="layui-input-block">
                <input type="hidden" name="thumb2" value="{$setting['thumb2']}" id="thumb2">
                <div id="preview-thumb2">
                    {if !empty($setting['thumb2'])}
                    <img src="{php echo cmf_get_upload_url($setting['thumb2'])}" alt="" width="200" height="150">
                    {/if}
                </div>
                <button type="button" class="layui-btn" id="thumb2-btn">
                    <i class="layui-icon">&#xe654;</i>上传图片
                </button>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="save" lay-submit="site">
                保存
            </button>
        </div>
    </form>
</div>
<script>
    layui.use('upload', function(){
        var upload = layui.upload;

        //执行实例
        var uploadInst1 = upload.render({
            elem: '#thumb1-btn', //绑定元素
            url: '{php echo $this->createWebUrl("setting",["op"=>"share","extra"=>"upload"])}', //上传接口
            size:4*1024,//4M
            done: function(res){
                if(res.code){
                    var html = "<img src='" + res.data + "' width='200' height='150'>"
                    $('#preview-thumb1').html(html)
                    $('#thumb1').val(res.data)
                }else{
                    layer.msg(res.msg, {icon: 0});
                }
            },error: function(){
                layer.msg("网络异常，请稍后重试", {icon: 0});
            }
        });

        var uploadInst2 = upload.render({
            elem: '#thumb2-btn', //绑定元素
            url: '{php echo $this->createWebUrl("setting",["op"=>"share","extra"=>"upload"])}', //上传接口
            size:4*1024,//4M
            done: function(res){
                if(res.code){
                    var html = "<img src='" + res.data + "' width='200' height='150'>"
                    $('#preview-thumb2').html(html)
                    $('#thumb2').val(res.data)
                }else{
                    layer.msg(res.msg, {icon: 0});
                }
            },error: function(){
                layer.msg("网络异常，请稍后重试", {icon: 0});
            }
        });
    });
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;

        //自定义验证规则
        form.verify({
            detail: function (value) {
                if (value.length < 1) {
                    return '分享详情不能为空';
                }
            }
        });

        //监听提交
        form.on('submit(save)', function (data) {
            console.log(data);
            var form_data = data.field
            //发异步，把数据提交给php
            var url = '{php echo $this->createWebUrl("setting",array("op"=>"share","extra"=>"save"))}'
            $.post(url, form_data, function (ret) {
                console.log(ret)
                if (ret.code) {
                    layer.msg(ret.msg, {icon: 1});
                } else {
                    layer.msg(ret.msg, {icon: 0});
                }
            }, 'json')
            return false;
        });


    });
</script>
<script>var _hmt = _hmt || [];
(function () {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>